n = input()
m = 0
if len(n) == 4:
    for o in range(0, 4):
        for i in range(o + 1, 5):
            f = int(n[o:i])
            l = 0
            for j in range(1,f + 1):
                if f % j == 0:
                    l = l + 1
            if l == 2:
                m = max(m,j)
print(m)
